<template>
  <div class="loginbody">
    <div class="logindata">
      <div class="logintext">
        <h2>Welcome</h2>
      </div>
      <div class="formdata">
        <el-form ref="form" :model="form" :rules="rules">
          <el-form-item prop="username">
            <el-input
                v-model="loginForm.username"
                clearable=""
                placeholder="请输入用户名">
            </el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
                type="password"
                v-model="loginForm.password"
                clearable=""
                placeholder="请输入密 码">
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="butt">
        <el-button
            type="primary"
            @click.native.prevent="login">
          登录
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>


export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: "Login",
  data() {
    return {
      loginForm:{
        username:'',
        password:''
      },
      checked: false,
      rules:{
        username:[{
          require:true,message:'请输入用户名',trigger:'blur'
        }],
        password: [{
          require:true,message:'请输入密 码',trigger:'blur'
        }]
      }
    }
  },
  mounted() {
    if (localStorage.getItem("news")){
      this.loginForm=JSON.parse(localStorage.getItem("news"))
      this.checked=true
    }
  },
  methods: {
    login(){
      this.$axios.post(this.$httpUrls+'/superuser/login',this.loginForm).then(res=>res.data).then(res=>{
        console.log(res)
        if (res.code==200){
          sessionStorage.setItem("CurUser",JSON.stringify(res.data))
          this.$router.replace('/index');
        }
      });
    },
    remember(data){
      this.checked=data
      if (this.checked){
        localStorage.setItem("news",JSON.stringify(this.loginForm))
      }else {
        localStorage.removeItem("news")
      }
    },
    reset() {
      this.username=''
      this.password=''
    }
  },
  beforeMount() {
    this.login();
    this.reset();
  }
};

</script>

<style>
.loginbody{
  width: 100%;
  height: 100%;
  min-width: 1000px;
  background-image: url("http://allhope.work/img/index.jpg");
  /*background-color: #588ec4;*/
  background-size: 100% 100%;
  background-position: center center;
  overflow: auto;
  background-repeat: no-repeat;
  position: fixed;
  line-height: 100%;
  padding-top: 150px;
}
.logintext{
  margin-bottom: 20px;
  line-height: 50px;
  text-align: center;
  font-size: 30px;
  font-weight: bolder;
  color: white;
  text-shadow: 2px 2px 4px #000000;
}
.logindata{
  width: 400px;
  height: 300px;
  transform: translate(-50%);
  margin-left: 50%;
}
.tool{
  display: flex;
  justify-content: space-between;
  color: #606266;
}
.butt{
  margin-top: 10px;
  text-align: center;
}

</style>
